package dc.exam;

import java.util.ArrayList;
import java.util.List;

public class TableInfo {

	private List<String> header;
	private List<List<String>> info;

	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append("<table>");
		if (header != null) {

			sb.append("<tr>");
			for (String h : header) {
				sb.append("<td>").append(h).append("</td>");
			}
			sb.append("</tr>");
		}

		if (info != null) {
			for (List<String> item : info) {
				if (item != null) {
					sb.append("<tr>");
					for (String h : item) {
						sb.append("<td>").append(h).append("</td>");
					}
					sb.append("</tr>");
				}
			}
		}
		sb.append("</table>");
		return sb.toString();

	}

	public TableInfo(List<String> header, List<List<String>> info) {
		super();
		this.header = header;
		this.info = info;
	}
	
	public static void main(String[] args) {
		List<String> header = new ArrayList<String>();
		header.add("aaa");
		header.add("bbb");
		header.add("ccc");
		
		List<String> c = new ArrayList<String>();
		c.add("11");
		c.add("22");
		c.add("33");
		
		List<List<String>> info = new ArrayList<List<String>>();
		info.add(c);
		
		TableInfo ti = new TableInfo(header, info);
		System.out.println(ti.toString());
	}

}
